Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(connector): [WorldPay] propagate refusal codes as error code and messages #6392

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

kashif-m
Copy link
Contributor

@kashif-m kashif-m commented Oct 22, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Described in #6316 (point # 2)

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Helps in error code unification for understanding the errors better.

How did you test it?

Tested locally using test cards and magic values for intentionally returning a refused response - https://developer.worldpay.com/products/access/card-payments/testing#test-card-numbers

Things to test

  1. Non 3DS payments
  2. 3DS payments
1. Non 3DS payments

Use magic values for cardHolderName - https://developer.worldpay.com/products/access/card-payments/testing#issuer-response-test-values

cURL

curl --location --request POST 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_sMl3D9efytjSoXznSOKCv5PHyql50M1BMhU8e7qsa5m6mXxHvyROVg7cER7AWue9' \
    --data-raw '{"amount":6500,"currency":"USD","confirm":true,"capture_method":"automatic","capture_on":"2022-09-10T10:11:12Z","customer_id":"cus_5A3VgopTFe8q83EEHgTq_4","email":"[email protected]","name":"John Doe","phone":"999999999","profile_id":"pro_OodaMoJ1Y9nlnegU4soR","phone_country_code":"+65","description":"Its my first payment request","authentication_type":"no_three_ds","return_url":"https://hyperswitch.io","setup_future_usage":"on_session","customer_acceptance":{"acceptance_type":"offline","accepted_at":"1963-05-03T04:07:52.723Z","online":{"ip_address":"127.0.0.1","user_agent":"amet irure esse"}},"connector":["worldpay"],"payment_method":"card","payment_method_type":"debit","payment_method_data":{"card":{"card_number":"5555555555554444","card_exp_month":"08","card_exp_year":"2025","card_holder_name":"REFUSED17","card_cvc":"123"}},"billing":{"address":{"line1":"1467","line2":"Harrison Street","line3":"Harrison Street","city":"San Fransico","state":"California","zip":"94122","country":"US","first_name":"John"}},"statement_descriptor_name":"joseph","statement_descriptor_suffix":"JS","metadata":{"udf1":"value1","new_customer":"true","login_date":"2019-09-10T10:11:12Z"},"browser_info":{"ip_address":"129.0.0.1","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","accept_header":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","language":"en-US","color_depth":30,"screen_height":1117,"screen_width":1728,"time_zone":-330,"java_enabled":true,"java_script_enabled":true}}'

Response

{"payment_id":"pay_EFdpMNQuatKoPldR0A5r","merchant_id":"merchant_1728979001","status":"failed","amount":6500,"net_amount":6500,"shipping_cost":null,"amount_capturable":0,"amount_received":null,"connector":"worldpay","client_secret":"pay_EFdpMNQuatKoPldR0A5r_secret_65zcOrh22VbhmfdHcj5a","created":"2024-10-22T11:00:07.527Z","currency":"USD","customer_id":"cus_5A3VgopTFe8q83EEHgTq_4","customer":{"id":"cus_5A3VgopTFe8q83EEHgTq_4","name":"John Doe","email":"[email protected]","phone":"999999999","phone_country_code":"+65"},"description":"Its my first payment request","refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":"on_session","off_session":null,"capture_on":null,"capture_method":"automatic","payment_method":"card","payment_method_data":{"card":{"last4":"4444","card_type":null,"card_network":null,"card_issuer":null,"card_issuing_country":null,"card_isin":"555555","card_extended_bin":null,"card_exp_month":"08","card_exp_year":"2025","card_holder_name":null,"payment_checks":null,"authentication_data":null},"billing":null},"payment_token":null,"shipping":null,"billing":{"address":{"city":"San Fransico","country":"US","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"California","first_name":"John","last_name":null},"phone":null,"email":null},"order_details":null,"email":"[email protected]","name":"John Doe","phone":"999999999","return_url":"https://hyperswitch.io/","authentication_type":"no_three_ds","statement_descriptor_name":"joseph","statement_descriptor_suffix":"JS","next_action":null,"cancellation_reason":null,"error_code":"17","error_message":"ANNULATION BY CLIENT","unified_code":"UE_000","unified_message":"Something went wrong","payment_experience":null,"payment_method_type":"debit","connector_label":null,"business_country":null,"business_label":"default","business_sub_label":null,"allowed_payment_method_types":null,"ephemeral_key":{"customer_id":"cus_5A3VgopTFe8q83EEHgTq_4","created_at":1729594807,"expires":1729598407,"secret":"epk_d27b564c47824d8fb87ad42da0dc5c65"},"manual_retry_allowed":true,"connector_transaction_id":"34a61c15-d8ab-4da2-b6f1-fa4ffdb494ee","frm_message":null,"metadata":{"udf1":"value1","login_date":"2019-09-10T10:11:12Z","new_customer":"true"},"connector_metadata":null,"feature_metadata":null,"reference_id":null,"payment_link":null,"profile_id":"pro_OodaMoJ1Y9nlnegU4soR","surcharge_details":null,"attempt_count":1,"merchant_decision":null,"merchant_connector_id":"mca_omabWO9B7CSmaCMuT6eh","incremental_authorization_allowed":false,"authorization_count":null,"incremental_authorizations":null,"external_authentication_details":null,"external_3ds_authentication_attempted":false,"expires_on":"2024-10-22T11:15:07.527Z","fingerprint":null,"browser_info":{"language":"en-US","time_zone":-330,"ip_address":"129.0.0.1","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","color_depth":30,"java_enabled":true,"screen_width":1728,"accept_header":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","screen_height":1117,"java_script_enabled":true},"payment_method_id":null,"payment_method_status":null,"updated":"2024-10-22T11:00:09.158Z","charges":null,"frm_metadata":null,"merchant_order_reference_id":null,"order_tax_amount":null,"connector_mandate_id":null}
2. 3DS payments

Use test card numbers - https://developer.worldpay.com/products/access/3ds/testing#test-card-number

cURL

curl --location --request POST 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_sMl3D9efytjSoXznSOKCv5PHyql50M1BMhU8e7qsa5m6mXxHvyROVg7cER7AWue9' \
    --data-raw '{"authentication_type":"three_ds","capture_method":"manual","customer_id":"cus_5A3VgopTFe8q83EEHgTq","profile_id":"pro_OodaMoJ1Y9nlnegU4soR","amount":100,"currency":"USD","confirm":true,"connector":["worldpay"],"billing":{"address":{"line1":"1467","line2":"Harrison Street","line3":"Harrison Street","city":"San Fransico","state":"CA","zip":"94122","country":"US","first_name":"John","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"}},"email":"[email protected]","session_expiry":10000,"return_url":"https://example.com","off_session":true,"payment_method":"card","payment_method_type":"credit","payment_method_data":{"card":{"card_number":"4000000000001125","card_exp_month":"12","card_exp_year":"2030","card_holder_name":"John Doe","card_cvc":"123"}},"browser_info":{"user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","accept_header":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","language":"en-US","color_depth":24,"screen_height":723,"screen_width":1536,"time_zone":0,"java_enabled":true,"java_script_enabled":true,"ip_address":"127.0.0.1"},"statement_descriptor_name":"John","statement_descriptor_suffix":"JD","metadata":{"udf1":"value1","new_customer":"true","login_date":"2019-09-10T10:11:12Z"}}'

Response

{"payment_id":"pay_ff5lUcN6X1lg5f2PBtyv","merchant_id":"merchant_1728979001","status":"requires_customer_action","amount":100,"net_amount":100,"shipping_cost":null,"amount_capturable":100,"amount_received":null,"connector":"worldpay","client_secret":"pay_ff5lUcN6X1lg5f2PBtyv_secret_6iktmiNQwi8DAsIRNn4i","created":"2024-10-21T11:03:31.227Z","currency":"USD","customer_id":"cus_sH6s3hf1uukqvYlAGkj5","customer":{"id":"cus_sH6s3hf1uukqvYlAGkj5","name":"John Doe","email":"[email protected]","phone":"999999999","phone_country_code":"+65"},"description":null,"refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":null,"off_session":true,"capture_on":null,"capture_method":"manual","payment_method":"card","payment_method_data":{"card":{"last4":"1096","card_type":null,"card_network":null,"card_issuer":null,"card_issuing_country":null,"card_isin":"520000","card_extended_bin":null,"card_exp_month":"12","card_exp_year":"2030","card_holder_name":null,"payment_checks":null,"authentication_data":null},"billing":null},"payment_token":null,"shipping":null,"billing":{"address":{"city":"San Fransico","country":"US","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"CA","first_name":"John","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":null},"order_details":null,"email":"[email protected]","name":"John Doe","phone":"999999999","return_url":"https://example.com/","authentication_type":"three_ds","statement_descriptor_name":"John","statement_descriptor_suffix":"JD","next_action":{"type":"redirect_to_url","redirect_to_url":"http://localhost:8080/payments/redirect/pay_ff5lUcN6X1lg5f2PBtyv/merchant_1728979001/pay_ff5lUcN6X1lg5f2PBtyv_1"},"cancellation_reason":null,"error_code":null,"error_message":null,"unified_code":null,"unified_message":null,"payment_experience":null,"payment_method_type":"credit","connector_label":null,"business_country":null,"business_label":"default","business_sub_label":null,"allowed_payment_method_types":null,"ephemeral_key":{"customer_id":"cus_sH6s3hf1uukqvYlAGkj5","created_at":1729508611,"expires":1729512211,"secret":"epk_739c58c7f7384fac89c7099e1cdae436"},"manual_retry_allowed":null,"connector_transaction_id":"eyJrIjoxLCJkIjoiQTRKMWZFZXlONnFqdGhHTWlmWDdYY2RzUVlIUzI2dEdLcEFPak9GRzNaczJJRGpBeDR3ekZaWWVqNDJzOTJkWiJ9","frm_message":null,"metadata":{"udf1":"value1","login_date":"2019-09-10T10:11:12Z","new_customer":"true"},"connector_metadata":null,"feature_metadata":null,"reference_id":"5b1cdf1c-26ea-42b1-b6e0-a02453ebf21f","payment_link":null,"profile_id":"pro_OodaMoJ1Y9nlnegU4soR","surcharge_details":null,"attempt_count":1,"merchant_decision":null,"merchant_connector_id":"mca_omabWO9B7CSmaCMuT6eh","incremental_authorization_allowed":null,"authorization_count":null,"incremental_authorizations":null,"external_authentication_details":null,"external_3ds_authentication_attempted":false,"expires_on":"2024-10-21T13:50:11.227Z","fingerprint":null,"browser_info":{"language":"en-US","time_zone":0,"ip_address":"127.0.0.1","user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","color_depth":24,"java_enabled":true,"screen_width":1536,"accept_header":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","screen_height":723,"java_script_enabled":true},"payment_method_id":null,"payment_method_status":null,"updated":"2024-10-21T11:03:31.677Z","charges":null,"frm_metadata":null,"merchant_order_reference_id":null,"order_tax_amount":null,"connector_mandate_id":null}

PSync cURL

curl --location --request GET 'http://localhost:8080/payments/pay_ICCmG6L9CNloIx7jEXYF?force_sync=true' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_sMl3D9efytjSoXznSOKCv5PHyql50M1BMhU8e7qsa5m6mXxHvyROVg7cER7AWue9'

Response

{"payment_id":"pay_ICCmG6L9CNloIx7jEXYF","merchant_id":"merchant_1728979001","status":"failed","amount":100,"net_amount":100,"shipping_cost":null,"amount_capturable":100,"amount_received":null,"connector":"worldpay","client_secret":"pay_ICCmG6L9CNloIx7jEXYF_secret_vo2mImXCVS5wBe4bek01","created":"2024-10-22T11:02:56.638Z","currency":"USD","customer_id":"cus_5A3VgopTFe8q83EEHgTq","customer":{"id":"cus_5A3VgopTFe8q83EEHgTq","name":"John Doe","email":"[email protected]","phone":"999999999","phone_country_code":"+65"},"description":null,"refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":null,"off_session":true,"capture_on":null,"capture_method":"manual","payment_method":"card","payment_method_data":{"card":{"last4":"1125","card_type":null,"card_network":null,"card_issuer":null,"card_issuing_country":null,"card_isin":"400000","card_extended_bin":null,"card_exp_month":"12","card_exp_year":"2030","card_holder_name":null,"payment_checks":null,"authentication_data":null},"billing":null},"payment_token":null,"shipping":null,"billing":{"address":{"city":"San Fransico","country":"US","line1":"1467","line2":"Harrison Street","line3":"Harrison Street","zip":"94122","state":"CA","first_name":"John","last_name":"Doe"},"phone":{"number":"8056594427","country_code":"+91"},"email":null},"order_details":null,"email":"[email protected]","name":"John Doe","phone":"999999999","return_url":"https://example.com/","authentication_type":"three_ds","statement_descriptor_name":"John","statement_descriptor_suffix":"JD","next_action":null,"cancellation_reason":null,"error_code":"3dsUnavailable","error_message":"3DS authentication unavailable from issuer","unified_code":"UE_000","unified_message":"Something went wrong","payment_experience":null,"payment_method_type":"credit","connector_label":null,"business_country":null,"business_label":"default","business_sub_label":null,"allowed_payment_method_types":null,"ephemeral_key":null,"manual_retry_allowed":true,"connector_transaction_id":"01944733-3110-4dab-afed-144d8021f76b","frm_message":null,"metadata":{"udf1":"value1","login_date":"2019-09-10T10:11:12Z","new_customer":"true"},"connector_metadata":null,"feature_metadata":null,"reference_id":"1ac1c0be-7a6a-4309-b3e5-3df7a7de06e7","payment_link":null,"profile_id":"pro_OodaMoJ1Y9nlnegU4soR","surcharge_details":null,"attempt_count":1,"merchant_decision":null,"merchant_connector_id":"mca_omabWO9B7CSmaCMuT6eh","incremental_authorization_allowed":false,"authorization_count":null,"incremental_authorizations":null,"external_authentication_details":null,"external_3ds_authentication_attempted":false,"expires_on":"2024-10-22T13:49:36.638Z","fingerprint":null,"browser_info":{"language":"en-US","time_zone":0,"ip_address":"127.0.0.1","user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","color_depth":24,"java_enabled":true,"screen_width":1536,"accept_header":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","screen_height":723,"java_script_enabled":true},"payment_method_id":null,"payment_method_status":null,"updated":"2024-10-22T11:03:11.537Z","charges":null,"frm_metadata":null,"merchant_order_reference_id":null,"order_tax_amount":null,"connector_mandate_id":null}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by just clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@kashif-m kashif-m added A-connector-compatibility Area: Connector compatibility R-waiting-on-L1 Review: Waiting on L1 reviewer labels Oct 22, 2024
@kashif-m kashif-m self-assigned this Oct 22, 2024
@kashif-m kashif-m requested a review from a team as a code owner October 22, 2024 10:34
Copy link

semanticdiff-com bot commented Oct 22, 2024

Review changes with SemanticDiff.

Analyzed 3 of 3 files.

Overall, the semantic diff is 25% smaller than the GitHub diff.

Filename Status
✔️ crates/router/src/connector/worldpay.rs 1.63% smaller
✔️ crates/router/src/connector/worldpay/response.rs 48.86% smaller
✔️ crates/router/src/connector/worldpay/transformers.rs 52.14% smaller

@kashif-m kashif-m linked an issue Oct 22, 2024 that may be closed by this pull request
2 tasks
@likhinbopanna likhinbopanna added this pull request to the merge queue Oct 22, 2024
Merged via the queue into main with commit 3d1a3cd Oct 22, 2024
23 of 25 checks passed
@likhinbopanna likhinbopanna deleted the worldpay-refusal-codes branch October 22, 2024 13:03
@SanchithHegde SanchithHegde removed the R-waiting-on-L1 Review: Waiting on L1 reviewer label Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-compatibility Area: Connector compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] Worldpay payments integration
6 participants